+2007-04-10 Matthias Clasen <mclasen@redhat.com>
+
+ * gdk/x11/xsettings-client.[hc]: Change the XSettingsWatchFunc
+ to return a Bool to indicate success. Update callers and
+ implementors. Based on a patch by Owen Taylor.
+
+ * gdk/x11/gdkevents-x11.c (gdk_xsettings_watch_cb): Don't
+ leak a reference to gdkwin.
+
2007-04-07 Xan Lopez <xan@gnome.org>
* gtk/gtknotebook.c (gtk_notebook_class_init):
static GSource *gdk_display_source_new (GdkDisplay *display);
static gboolean gdk_check_xpending (GdkDisplay *display);
-static void gdk_xsettings_watch_cb (Window window,
+static Bool gdk_xsettings_watch_cb (Window window,
Bool is_start,
long mask,
void *cb_data);
return GDK_FILTER_CONTINUE;
}
-static void
+static Bool
gdk_xsettings_watch_cb (Window window,
Bool is_start,
long mask,
if (is_start)
{
- if (!gdkwin)
- gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
-
+ if (gdkwin)
+ g_object_ref (gdkwin);
+ else
+ {
+ gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
+
+ /* gdk_window_foreign_new_for_display() can fail and return NULL if the
+ * window has already been destroyed.
+ */
+ if (!gdkwin)
+ return False;
+ }
+
gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
}
else
{
- if (gdkwin)
- gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
+ if (!gdkwin)
+ {
+ /* gdkwin should not be NULL here, since if starting the watch succeeded
+ * we have a reference on the window. It might mean that the caller didn't
+ * remove the watch when it got a DestroyNotify event. Or maybe the
+ * caller ignored the return value when starting the watch failed.
+ */
+ g_warning ("gdk_xsettings_watch_cb(): Couldn't find window to unwatch");
+ return False;
+ }
+
+ gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
+ g_object_unref (gdkwin);
}
+
+ return True;
}
#define __GDK_EVENTS_X11_C__
XFlush (client->display);
if (client->manager_window && client->watch)
- client->watch (client->manager_window, True,
- PropertyChangeMask | StructureNotifyMask,
- client->cb_data);
+ {
+ if (!client->watch (client->manager_window, True,
+ PropertyChangeMask | StructureNotifyMask,
+ client->cb_data))
+ {
+ /* Inability to watch the window probably means that it was destroyed
+ * after we ungrabbed
+ */
+ client->manager_window = None;
+ return;
+ }
+ }
+
read_settings (client);
}